A touch of JavaScript (L040)

Just For Fun...

Eight Simple JavaScript Snippets

1)

Back Button / Forward Button

onclick="javascript: history.go(-1)"
onclick="javascript: history.forward(1)

Example
< input type="button" value="Back Button" onClick="javascript: history.go(-1)">
2)

Close Window Button

onclick="javascript: window.close()"

Example
< input type="button" value="Close Window" onclick="window.close()">
3)
Write the Current Date and Time Example
< script>document.write(new Date())< /script> Fri Sep 13 2019 22:43:38 GMT-0400 (Eastern Daylight Time)
4)

Status Bar Link Description

Example
< body onload="window.status='WebDev13';"> Move your mouse over < a href="#" onmouseover="window.status='Ukulukulele'; return true">this link</a> and view your status bar. < /body> this link

5)

Window Print Method

< b>Example< /b>< br> < input class="noPrint" type="button" value="Print This Page" onclick="window.print()">

6)

Tag Highlighter

Example
< style type="text/css"> input.this {background:black; color:white} input.that {background:white; color:black} < /style> < input type="button" value="Move Your Cursor Here" class="this" onmouseover="this.className='that'" onmouseout="this.className='this'">

7)

Select/Highlight Text

Example
< form name="aaae"> < textarea name="txt5" wrap="hard" cols="40" rows="5" readonly="readonly"> Click on the button below to highlight this text. < /textarea><br> < input type="button" value="Highlight All" onclick="javascript:this.form.txt5.focus();this.form.txt5.select();"> < /form>


8)

Use the <noscript> tag to redirect a browser when JavaScript is turned off

Example
< noscript> < meta http-equiv="refresh" content="0; URL=oldbrowser.htm"> < /noscript>